home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / pippki.jar / content / pippki / editcerts.js < prev    next >
Encoding:
Text File  |  2007-11-13  |  8.6 KB  |  267 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Bob Lord <lord@netscape.com>
  23.  *   Ian McGreer <mcgreer@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. const nsIX509Cert = Components.interfaces.nsIX509Cert;
  40. const nsX509CertDB = "@mozilla.org/security/x509certdb;1";
  41. const nsIX509CertDB = Components.interfaces.nsIX509CertDB;
  42. const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock;
  43.  
  44. var certdb;
  45. var cert;
  46.  
  47. function setWindowName()
  48. {
  49.   var dbkey = self.name;
  50.  
  51.   //  Get the cert from the cert database
  52.   certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB);
  53.   //var pkiParams = window.arguments[0].QueryInterface(nsIPKIParamBlock);
  54.   //var isupport = pkiParams.getISupportAtIndex(1);
  55.   //cert = isupport.QueryInterface(nsIX509Cert);
  56.   cert = certdb.findCertByDBKey(dbkey, null);
  57.  
  58.   var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  59.   var windowReference = document.getElementById('editCaCert');
  60.  
  61.   var message1 = bundle.formatStringFromName("editTrustCA",
  62.                                              [ cert.commonName ],
  63.                                              1);
  64.   setText("certmsg", message1);
  65.  
  66.   var ssl = document.getElementById("trustSSL");
  67.   if (certdb.isCertTrusted(cert, nsIX509Cert.CA_CERT, 
  68.                           nsIX509CertDB.TRUSTED_SSL)) {
  69.     ssl.setAttribute("checked", "true");
  70.   } else {
  71.     ssl.setAttribute("checked", "false");
  72.   }
  73.   var email = document.getElementById("trustEmail");
  74.   if (certdb.isCertTrusted(cert, nsIX509Cert.CA_CERT, 
  75.                           nsIX509CertDB.TRUSTED_EMAIL)) {
  76.     email.setAttribute("checked", "true");
  77.   } else {
  78.     email.setAttribute("checked", "false");
  79.   }
  80.   var objsign = document.getElementById("trustObjSign");
  81.   if (certdb.isCertTrusted(cert, nsIX509Cert.CA_CERT,  
  82.                           nsIX509CertDB.TRUSTED_OBJSIGN)) {
  83.     objsign.setAttribute("checked", "true");
  84.   } else {
  85.     objsign.setAttribute("checked", "false");
  86.   }
  87. }
  88.  
  89. function doOK()
  90. {
  91.   var ssl = document.getElementById("trustSSL");
  92.   var email = document.getElementById("trustEmail");
  93.   var objsign = document.getElementById("trustObjSign");
  94.   var trustssl = (ssl.checked) ? nsIX509CertDB.TRUSTED_SSL : 0;
  95.   var trustemail = (email.checked) ? nsIX509CertDB.TRUSTED_EMAIL : 0;
  96.   var trustobjsign = (objsign.checked) ? nsIX509CertDB.TRUSTED_OBJSIGN : 0;
  97.   //
  98.   //  Set the cert trust
  99.   //
  100.   certdb.setCertTrust(cert, nsIX509Cert.CA_CERT, 
  101.                       trustssl | trustemail | trustobjsign);
  102.   return true;
  103. }
  104.  
  105. function doLoadForSSLCert()
  106. {
  107.   var dbkey = self.name;
  108.  
  109.   //  Get the cert from the cert database
  110.   certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB);
  111.   cert = certdb.findCertByDBKey(dbkey, null);
  112.  
  113.   var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  114.   var windowReference = document.getElementById('editWebsiteCert');
  115.  
  116.   var message1 = bundle.formatStringFromName("editTrustSSL",
  117.                                              [ cert.commonName ],
  118.                                              1);
  119.   setText("certmsg", message1);
  120.  
  121.   setText("issuer", cert.issuerName);
  122.  
  123.   var cacert = getCaCertForEntityCert(cert);
  124.   if(cacert == null)
  125.   {
  126.      setText("explanations", bundle.GetStringFromName("issuerNotKnown"));
  127.   }
  128.   else if(certdb.isCertTrusted(cacert, nsIX509Cert.CA_CERT,
  129.                                                 nsIX509CertDB.TRUSTED_SSL))
  130.   {
  131.      setText("explanations", bundle.GetStringFromName("issuerTrusted"));
  132.   }
  133.   else
  134.   {
  135.      setText("explanations", bundle.GetStringFromName("issuerNotTrusted"));
  136.   }
  137. /*
  138.   if(cacert == null)
  139.   {
  140.      var editButton = document.getElementById('editca-button');
  141.      editButton.setAttribute("disabled","true");
  142.   }
  143. */  
  144.   var trustssl = document.getElementById("trustSSLCert");
  145.   var notrustssl = document.getElementById("dontTrustSSLCert");
  146.   if (certdb.isCertTrusted(cert, nsIX509Cert.SERVER_CERT, 
  147.                           nsIX509CertDB.TRUSTED_SSL)) {
  148.     trustssl.radioGroup.selectedItem = trustssl;
  149.   } else {
  150.     trustssl.radioGroup.selectedItem = notrustssl;
  151.   }
  152. }
  153.  
  154. function doSSLOK()
  155. {
  156.   var ssl = document.getElementById("trustSSLCert");
  157.   //var checked = ssl.getAttribute("value");
  158.   var trustssl = ssl.selected ? nsIX509CertDB.TRUSTED_SSL : 0;
  159.   //
  160.   //  Set the cert trust
  161.   //
  162.   certdb.setCertTrust(cert, nsIX509Cert.SERVER_CERT, trustssl);
  163.   return true;
  164. }
  165.  
  166. function doLoadForEmailCert()
  167. {
  168.   var dbkey = self.name;
  169.  
  170.   //  Get the cert from the cert database
  171.   certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB);
  172.   cert = certdb.findCertByDBKey(dbkey, null);
  173.  
  174.   var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  175.   var windowReference = document.getElementById('editEmailCert');
  176.  
  177.   var message1 = bundle.formatStringFromName("editTrustEmail",
  178.                                              [ cert.commonName ],
  179.                                              1);
  180.   setText("certmsg", message1);
  181.  
  182.   setText("issuer", cert.issuerName);
  183.  
  184.   var cacert = getCaCertForEntityCert(cert);
  185.   if(cacert == null)
  186.   {
  187.      setText("explanations", bundle.GetStringFromName("issuerNotKnown"));
  188.   }
  189.   else if(certdb.isCertTrusted(cacert, nsIX509Cert.CA_CERT,
  190.                                                 nsIX509CertDB.TRUSTED_EMAIL))
  191.   {
  192.      setText("explanations", bundle.GetStringFromName("issuerTrusted"));
  193.   }
  194.   else
  195.   {
  196.      setText("explanations", bundle.GetStringFromName("issuerNotTrusted"));
  197.   }
  198. /*
  199.   if(cacert == null)
  200.   {
  201.      var editButton = document.getElementById('editca-button');
  202.      editButton.setAttribute("disabled","true");
  203.   }
  204. */  
  205.   var trustemail = document.getElementById("trustEmailCert");
  206.   var notrustemail = document.getElementById("dontTrustEmailCert");
  207.   if (certdb.isCertTrusted(cert, nsIX509Cert.EMAIL_CERT, 
  208.                           nsIX509CertDB.TRUSTED_EMAIL)) {
  209.     trustemail.radioGroup.selectedItem = trustemail;
  210.   } else {
  211.     trustemail.radioGroup.selectedItem = notrustemail;
  212.   }
  213. }
  214.  
  215. function doEmailOK()
  216. {
  217.   var email = document.getElementById("trustEmailCert");
  218.   //var checked = ssl.getAttribute("value");
  219.   var trustemail = email.selected ? nsIX509CertDB.TRUSTED_EMAIL : 0;
  220.   //
  221.   //  Set the cert trust
  222.   //
  223.   certdb.setCertTrust(cert, nsIX509Cert.EMAIL_CERT, trustemail);
  224.   return true;
  225. }
  226.  
  227. function editCaTrust()
  228. {
  229.    var cacert = getCaCertForEntityCert(cert);
  230.    if(cacert != null)
  231.    {
  232.       window.openDialog('chrome://pippki/content/editcacert.xul', cacert.dbKey,
  233.                         'chrome,centerscreen,modal');
  234.    }
  235.    else
  236.    {
  237.       var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  238.       alert(bundle.GetStringFromName("issuerCertNotFound"));
  239.    }
  240. }
  241.  
  242. function getCaCertForEntityCert(cert)
  243. {
  244.    var i=1;
  245.    var nextCertInChain;
  246.    nextCertInChain = cert;
  247.    var lastSubjectName="";
  248.    while(true)
  249.    {
  250.      if(nextCertInChain == null)
  251.      {
  252.         return null;
  253.      }
  254.      if((nextCertInChain.type == nsIX509Cert.CA_CERT) || 
  255.                                  (nextCertInChain.subjectName = lastSubjectName))
  256.      {
  257.         break;
  258.      }
  259.  
  260.      lastSubjectName = nextCertInChain.subjectName;
  261.      nextCertInChain = nextCertInChain.issuer;
  262.    }
  263.  
  264.    return nextCertInChain;
  265. }
  266.  
  267.